home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / obero / oberon_lib.lha / oberon-a / source1.lha / source / AmigaUtil / DosUtil.mod < prev    next >
Text File  |  1994-08-08  |  2KB  |  76 lines

  1. (***************************************************************************
  2.  
  3.      $RCSfile: DosUtil.mod $
  4.   Description: Support for clients of dos.library
  5.  
  6.    Created by: fjc (Frank Copeland)
  7.     $Revision: 3.2 $
  8.       $Author: fjc $
  9.         $Date: 1994/08/08 16:09:42 $
  10.  
  11.   Copyright © 1994, Frank Copeland.
  12.   This file is part of the Oberon-A Library.
  13.   See Oberon-A.doc for conditions of use and distribution.
  14.  
  15. ***************************************************************************)
  16.  
  17. MODULE DosUtil;
  18.  
  19. (*
  20. ** $C- CaseChk       $I= IndexChk  $L+ LongAdr   $N- NilChk
  21. ** $P- PortableCode  $R- RangeChk  $S- StackChk  $T- TypeChk
  22. ** $V- OvflChk       $Z- ZeroVars
  23. *)
  24.  
  25. IMPORT Exec, Dos, Str := Strings;
  26.  
  27. (*------------------------------------*)
  28. PROCEDURE FileExists * (path : ARRAY OF CHAR) : BOOLEAN;
  29.  
  30.   VAR lock : Dos.FileLockPtr; result : BOOLEAN;
  31.  
  32. (* $D- disable copying of open arrays *)
  33. BEGIN (* FileExists *)
  34.   result := FALSE;
  35.   lock := Dos.base.Lock (path, Dos.sharedLock);
  36.   IF lock # NIL THEN result := TRUE; Dos.base.UnLock (lock) END;
  37.   RETURN result
  38. END FileExists;
  39.  
  40. (*------------------------------------*)
  41. (*
  42.   Searches for "file" in the current directory first, followed by the
  43.   directories listed in "paths".  If it is found the procedure returns TRUE
  44.   and the full pathname of the file is returned in "fullPath".  If not, the
  45.   procedure returns FALSE and fullPath is set to "".
  46. *)
  47.  
  48. PROCEDURE Search *
  49.   ( VAR paths    : ARRAY OF Exec.STRPTR;
  50.         file     : ARRAY OF CHAR;
  51.     VAR fullPath : ARRAY OF CHAR)
  52.   : BOOLEAN;
  53.  
  54.   VAR index : INTEGER; len : LONGINT; ch : CHAR;
  55.  
  56. (* $D- disable copying of open arrays *)
  57. BEGIN (* Search *)
  58.   fullPath [0] := 0X; index := 0;
  59.   LOOP
  60.     Str.Append (fullPath, file);
  61.     IF FileExists (fullPath) THEN RETURN TRUE END;
  62.     IF paths [index] = NIL THEN
  63.       fullPath [0] := 0X; RETURN FALSE
  64.     ELSE
  65.       COPY (paths [index]^, fullPath); INC (index);
  66.       len := Str.Length (fullPath);
  67.       IF len > 0 THEN
  68.         ch := fullPath [len - 1];
  69.         IF (ch # ":") & (ch # "/") THEN Str.Append (fullPath, "/") END
  70.       END
  71.     END
  72.   END
  73. END Search;
  74.  
  75. END DosUtil.
  76.